import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import Nprogress from "nprogress"
import "nprogress/nprogress.css"
Nprogress.configure({showSpinner:false})
Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})






//注册全局前置守卫函数
router.beforeEach((to,from,next)=>{
    Nprogress.start()
    document.title=to.meta&&to.meta.title||"饿了么滴"
    var token=localStorage.getItem("token")
    if(to.path=="/index/order"||to.path=="/index/mine"){
      if(token){
        next()
      }else{
        next("/denglu")
      }
    }else{
      next()
    }
})

//注册 全局后置守卫函数
router.afterEach((to,from)=>{
      Nprogress.done()
})

export default router
